Skip to content

Preserve callable identity and arguments through std::bind - #302

Merged
DrSergei merged 1 commit into
masterfrom
tmp
Dec 1, 2026
Merged

DrSergei merged 1 commit into
masterfrom
tmp

Conversation

@DrSergei

Copy link
Copy Markdown
Member

Represent each concrete binding as a callable value carrying its target, receiver, stored arguments, and placeholder mapping through copies, fields, parameters, and returns. Compose those bindings at invocation and use the same arguments for model wiring, callback discovery, and execution contexts. Reserve a slot for a model-supplied stop token.

Use C++ lookup to identify standard bind and resolve explicitly cast targets. Carry results through brace initialization and recognize globally qualified placeholders without the standard declaration. Keep runtime and ambiguous targets opaque. Document packaged-task storage and external SDK dispatch as separate gaps.

Export provenance for each binding across configuration variants and deduplicate identical captured and forwarded argument-flow rows.

Validate with cargo test --workspace, 13 focused bind tests, 198 default and 90 canonical pinned-corpus checks, and matching one-job and eight-job regression exports. Canonical debug HiView and Camera passed 50 checks.

Closes #243

Comment thread docs/MODELS.md Resolved
@devnullexile-deepseek-review

devnullexile-deepseek-review Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

PR Reviewer Guide 🔍

(Review updated until commit bae8a97)

Here are some key observations to aid the review process:

🎫 Ticket compliance analysis 🔶

243 - Partially compliant

Compliant requirements:

  • Reproduction targets and no eager bind execution (fixture tests).
  • Stored arguments, _1/_2 reordering, repeated placeholders, member receiver binding, and return-value flow tests.
  • Copy/parameter/field/return/cross-TU flow and distinct-bindings-to-one-function tests.
  • Modeled thread/timer invocation with argument mapping and execution contexts.
  • Shared std::bind lookup gating and user-defined bind exclusion tests.
  • Conservative/documented opaque subset; packaged-task and external SDK gaps documented.
  • Corpus-style timer registration (tests/fixtures/std_bind, AddTimerEvent).

Non-compliant requirements:

  • None identified.

Requires further human verification:

  • cargo test --workspace outcome (not executed in this review).
  • Pinned-corpus expectation updates reviewed semantically, and one-job vs eight-job determinism.
⏱️ Estimated effort to review: 4 🔵🔵🔵🔵⚪
✅ Merge recommendation: Needs review
🧪 PR contains tests
🔒 No security concerns identified
⚡ Recommended focus areas for review

Off-by-one reference index

For a member-function bind target, index already counts bound arguments
from the start of the target's parameter list (slot 0 is the receiver and
maps to the implicit this; slot 1 maps to the first explicit parameter).
The code instead looks up the reference mode at index - receiver, so with
receiver = 1 a dereferenced bound argument for explicit parameter k is
checked against reference_params[k-1] (for k = 1, against this).
Example: for void Worker::run(Callback&) and
std::bind(&Worker::run, w, *slot), the dereference is modeled with
this's non-reference mode instead of Callback&, so *slot is treated
as a loaded value rather than an alias to slot; the bound argument (and
any callback reachable only through that alias) can be mis-modeled.
bind_member_with_dereferenced_callback uses a by-value parameter, so it
does not cover this case. This assumes reference_params is parallel to
Function::params including this, which is how wire_bound_callable
zips bound slots onto params; please verify. If so, index
reference_params with the target formal position directly (keep
receiver only to identify the receiver slot, do not subtract it).

let reference = explicit.and_then(|(callee, receiver)| {
    index
        .checked_sub(receiver)
        .and_then(|param| parameter_reference(program, callee, param))
});
✅ Resolved findings

docs/MODELS.md:413

Stale documentation

The built-in-models row for std::packaged_task::packaged_task still explains itself with "a bind result is not a function, so the bind site makes the edge". That is no longer true after this PR: a bind result now carries a Bound location whose target fn_for_loc returns, invoke_targets explicitly yields no targets for a bound value at the packaged-task constructor, and the std::bind model was removed (the added eval probes assert zero indirect edges at std::bind sites). The row now contradicts both the code and the new "Callable wrappers" prose in the same file, and readers using it to reason about packaged-task reachability will get the wrong model. Reword the parenthetical to state that a bound value's edge comes from its invocation site, and that the constructor keeps the legacy edge only for ordinary function values.

@devnullexile-deepseek-review

devnullexile-deepseek-review Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

DeepSeek review: Not approved (bae8a97)

To get the bot's approval:

  • Fix, or answer in its thread: crates/trace-parse/src/lower.rs:10457 Off-by-one reference index: For a member-function bind target, `index` already counts bound arguments from the start of the target's parameter list (slot 0 is the receiver and maps to the implicit `this`; slot 1 maps to the first explicit parameter). The code instead looks up the reference mode at `index - receiver`, so with…
  • merge recommendation is 'needs_review'

This comment is updated on every review. The review comment and its threads have the details.

@devnullexile devnullexile left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The overall BindCallable representation and solver composition are well structured, with solid test and eval coverage. Found three functional edge-case bugs (dereferenced stored args, &x/&obj.field stored args, and lambda-free projection for bound lambdas) plus one minor inspect dataflow classification gap.

Comment thread crates/trace-parse/src/lower.rs Outdated
let binding = if let Some(n) = bind_placeholder(program, ctx, spelled) {
BoundArg::Placeholder(n)
} else if let Some(&(_, var)) = args.var_args.iter().find(|(at, _)| *at == position) {
BoundArg::Stored(var)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Dereferenced C++ arguments such as std::bind(Run, *slot) lose their load because lower_std_bind reads args.var_args before args.for_callee resolves args.deref_args. For Callback *slot, args.var_args still holds the raw pointer slot rather than the loaded *slot value, so BoundArg::Stored(slot) wires the pointer instead of the callback into Run's parameter and misses Run -> Target. Resolve any matching DerefArg entry (as CallArgs::for_callee does, using the target's reference_params or None when unknown) before storing the variable.

Comment thread crates/trace-analysis/src/solver.rs Outdated
call_site: cs.id,
arg_index: index,
actual_var,
actual_address: None,

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Stored address-of arguments such as std::bind(&Worker::run, &worker) or std::bind(memset, &x, 0, sizeof(x)) drop addr_of_args and addr_of_member_args metadata when lowered into BoundArg::Stored(temp). At invocation, wire_bound_callable records actual_var: Some(temp) with actual_address: None (so arg_flow_edges reports the synthetic $ret temporary instead of worker/x), and compose_bound_site omits those positions from addr_of_args and addr_of_member_args (so Effect::Clears attaches its terminator to $ret, record_model_forwarded reports $ret, and Effect::Alias loses its member-address guard for &obj.field). Preserve address-of / member-address flags on stored arguments and resolve them via pag.argument_var / actual_address as append_argument_rows does.

let kind_str = crate::inspect::loc_kind_schema_str(loc.kind);
let label = match (loc.kind, loc.var) {
(LocKind::Function, _) => format!("fn:{}", loc.desc),
(LocKind::Bound, _) => format!("bind:{}", loc.desc),

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P2] Exporting Bound locations with label bind:<desc> and kind Bound bypasses lambda sanitization in crates/trace-db/src/projection.rs (lines 713-727), which only matches label LIKE 'fn:%' and locations.kind = 'Function'. When std::bind wraps a lambda inside outer() (e.g. std::bind([](int) {}, 1)), the subsequent projection pass remaps the bound node's fn_id to outer and strips ::$lambda... from its label and description, corrupting the public flow_nodes and locations rows into claiming the binding wraps outer instead of anonymous callable with fn_id = NULL.

LocKind::ArraySummary => "array_summary",
LocKind::Function => "function",
LocKind::StringLit => "string_lit",
LocKind::Bound => "bound",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[P3] crates/trace-db/src/dataflow.rs was not updated for the new "bound" flow_nodes.detail tag: lines 552 and 609 only match detail == "function". In trace inspect dataflow, a Bound location node therefore reads the NULL variable file/line columns instead of the target function's location (producing an empty path and line 0) and keeps kind = "loc" instead of "function" (unlike inspect/slice.rs:383), preventing lines 1544 and 1559 from rendering it as a function origin.

@devnullexile-deepseek-review devnullexile-deepseek-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated DeepSeek review found no blocking concerns in ff09cb9.

Represent each binding as a callable value carrying its target, receiver,
stored arguments, and placeholder mapping through copies, fields,
parameters, and returns. Compose the bindings at invocation for argument
flow, callback discovery, and execution contexts. Reserve a slot for a
model-supplied stop token.

Use C++ lookup to identify standard bind and resolve explicitly cast
targets. Preserve forwarded functions and lambdas as their targets
resolve, and summarize a trailing argument pack across remaining formals.
Register zero-argument model watchers when a callback variable acquires
a bound value. Cover local brace initialization and globally qualified
placeholders. Document packaged-task storage and external SDK dispatch.

Apply ordinary dereference rules to stored arguments. Preserve explicit
addresses and member-address fallback metadata for argument flow and
function models. Retain bound lambda targets in raw exports and publish
them as anonymous callables. Display named bound targets as function
origins in dataflow inspection.

Export provenance for each resolved target, including across configuration
variants, and deduplicate identical captured and forwarded argument-flow
rows.

Validate with cargo test --workspace, 19 focused bind tests, and 51
canonical debug HiView and Camera checks. The expanded regression fixture
produces matching one-job and eight-job exports. The earlier pinned
comparison passed 199 default and 91 canonical checks across all four
corpora, with matching exports at both job counts.

Closes #243
@devnullexile-deepseek-review
devnullexile-deepseek-review Bot dismissed their stale review November 30, 2026 14:29

Automated DeepSeek review of bae8a97 did not pass: merge recommendation is 'needs_review'; 1 finding(s) on lines changed since the last review.

devnullexile added a commit to LHCWN/dsh-triage-desk that referenced this pull request Nov 30, 2026
Review prompts re-read the head commit right before posting, review newer
commits first, and pass the reviewed head as commit_id. A force-push during
a review left LHCWN/pathologist#302 reviewed on an outdated commit, so it
returned as "new commits since your review". The previous texts stay in
LEGACY_BUILTIN_PROMPTS so unedited saved copies upgrade.

Review rows name who approved the PR and mark bots, from a new additive
approvedBy field (each other reviewer's latest approval or change request).
An older host keeps the generic "already approved by others" label.

@devnullexile devnullexile left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All four earlier comments are resolved in bae8a97 (dereferenced target/argument loads, stored address-of and member-address metadata, lambda-free projection for Bound locations, and dataflow.rs handling of detail == "bound"), with focused regression tests for each. No new issues found in the changes since 5603ae7.

@ArcsinX ArcsinX left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@DrSergei
DrSergei merged commit 55160b2 into master Dec 1, 2026
8 of 9 checks passed
@DrSergei
DrSergei deleted the tmp branch December 1, 2026 16:19
@IvanTrofimov052
IvanTrofimov052 restored the tmp branch December 2, 2026 09:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Preserve callable identity and argument bindings through std::bind

3 participants